<template>
  <div>
      <sbuncate :data='ncatelist' @cid="getcid"/>
    <van-field
      v-model="form.name"
      name="name"
      label="名称"
      placeholder="名称"
      :rules="[{ required: true, message: '请填写名称' }]"
    />
    <van-field
      v-model="form.description"
      name="description"
      label="描述"
      placeholder="描述"
    />
    <van-field
      v-model="form.tname"
      name="tname"
      label="讲师"
      placeholder="讲师"
      :rules="[{ required: true, message: '请填写讲师' }]"
    />

    图片:<van-uploader :after-read="afterpic" /> 视频：<van-uploader
      :after-read="aftermp4" v-model="fileList" multiple :max-count="3" accept=".mp4"
    />
    <van-button round block type="info" name="button1" native-type="submit"
      >登录</van-button
    >
  </div>
</template>

<script>
import sbuncate from './sbuncate.vue';
export default {
    components:{
        'sbuncate':sbuncate
    },
  data() {
    return {
      form: {},
      ncatelist:[],
      fileList:[],
      cid:0
    };
  },
  methods: {
    afterpic(file) {
      // 此时可以自行将文件上传至服务器
      //传文件 重新构造一个data
            let data = new FormData()
            data.append('id',1)
            data.append('file',file.file)
            this.$axios.post('/upload',data).then(res=>{
                //视频
                if(res.data.code==200){
                    alert('添加成功')
                }
                
            })
      console.log(file);
    },
     aftermp4(file) {
      // 此时可以自行将文件上传至服务器
      //传文件 重新构造一个data  
          for(var i =0;i<this.fileList.length;i++){
                this.afterRead(this.fileList[i],2)
            }
      console.log(file);
    },
    get_ncate(){
        this.$axios.get('/add_ncate')
        .then((res) => {
            this.ncatelist = res.data.list
            
        }).catch((err) => {
            
        });
    },
      getcid(v){
            //更新分类id
           this.cid=v
        },
  },
  mounted() {
      this.get_ncate()
  },
};
</script>

<style scoped>
</style>